<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>08_v-bind案例</title>
    <style>
        .red {
            color: red;
        }

        [v-cloak] {
            display: none;
        }
    </style>
</head>

<body>
<!-- 需求:点击某个电影,这个电影文本就变成红色 -->
<div id="app" v-cloak>
    <ul>
        <li v-for="(movie,index) in movies" v-on:click="changeColor(index)" :class="{red:currentIndex == index}">
            {{index}}---{{movie}}
        </li>
    </ul>
</div>

</body>

<script src="../vue.js"></script>
<script>
    const vm = new Vue({
        el: '#app',
        data: {
            movies: ['肖生客的救赎', '阿甘正传', '蝙蝠侠'],
            currentIndex: -1,
        },
        methods: {
            changeColor(index) {
                this.currentIndex = index
            }
        }
    })
</script>

</html>
